home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / overview / dtscpluslibrary / sources / graphicsenv.cp < prev    next >
Encoding:
Text File  |  2000-06-23  |  4.8 KB  |  185 lines

  1. /*
  2.     File:        GraphicsEnv.cp
  3.  
  4.     Contains:    GraphicsEnv is a collection of utility classes that could be used for defining grafport values
  5.                   (font, pen drawing, color).
  6.                 GraphicsEnv.cp contains the graphics environment member functions. 
  7.     
  8.     Written by: Kent Sandvik    
  9.  
  10.     Copyright:    Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
  11.  
  12.                 You may incorporate this Apple sample source code into your program(s) without
  13.                 restriction. This Apple sample source code has been provided "AS IS" and the
  14.                 responsibility for its operation is yours. You are not permitted to redistribute
  15.                 this Apple sample source code as "Apple sample source code" after having made
  16.                 changes. If you're going to re-distribute the source, we require that you make
  17.                 it clear in the source that the code was descended from Apple sample source
  18.                 code, but that you've made changes.
  19.  
  20.     Change History (most recent first):
  21.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  22.                 
  23.  
  24. */
  25. #ifndef _GRAPHICSENV_
  26. #include "GraphicsEnv.h"
  27. #endif
  28.  
  29.  
  30. // _________________________________________________________________________________________________________ //
  31. //    TFontEnvironment member functions.
  32. // CONSTRUCTORS AND DESTRUCTORS
  33. #pragma segment GraphicsEnv
  34. TFontEnvironment::TFontEnvironment(short mode,
  35.                                    short fontNo,
  36.                                    short textSize,
  37.                                    Style newStyle)
  38. // Set font values in grafport, default values: system font, 12 point, plain text.
  39. {
  40.     fMode = mode;
  41.     fFont = fontNo;
  42.     fTextSize = textSize;
  43.     fStyle = newStyle;
  44. }
  45.  
  46.  
  47. #pragma segment GraphicsEnv
  48. TFontEnvironment::~TFontEnvironment()
  49. // Default constructor -- not used for the time being.
  50. {
  51. }
  52.  
  53.  
  54. // MAIN INTERFACE
  55. #pragma segment GraphicsEnv
  56. void TFontEnvironment::Set()
  57. // Set current grafport to defined values concerning fonts.
  58. {
  59.     ::TextMode(fMode);                            // set copy mode
  60.     ::TextFont(fFont);                            // set font in current GrafPort
  61.     ::TextSize(fTextSize);                        // set font size in current GrafPort
  62.     ::TextFace(fStyle);                            // set font style in current GrafPort
  63. }
  64.  
  65.  
  66. #pragma segment GraphicsEnv
  67. void TFontEnvironment::Reset()
  68. // Reset the grafport font information to default state.
  69. {
  70.     ::TextMode(srcOr);                            // reset copy mode
  71.     ::TextFont(0);                                // reset font in current GrafPort
  72.     ::TextSize(0);                                // reset font size in current GrafPort
  73.     ::TextFace(0);                                // reset font style in current GrafPort
  74. }
  75.  
  76.  
  77. // _________________________________________________________________________________________________________ //
  78. //    TPenEnvironment member functions.
  79. // CONSTRUCTORS AND DESTRUCTORS
  80. #pragma segment GraphicsEnv
  81. TPenEnvironment::TPenEnvironment(short mode,
  82.                                  Pattern penPattern,
  83.                                  short penWidth,
  84.                                  short penHigh)
  85. // Set the grafport pen values concerning pattern, mode and size.
  86. {
  87.     fMode = mode;
  88.     fPattern = &penPattern;
  89.     fWidth = penWidth;
  90.     fHigh = penHigh;
  91. }
  92.  
  93.  
  94. #pragma segment GraphicsEnv
  95. TPenEnvironment::~TPenEnvironment()
  96. // Default destructor -- not used for the time being.
  97. {
  98. }
  99.  
  100.  
  101. // MAIN INTERFACE
  102. #pragma segment GraphicsEnv
  103. void TPenEnvironment::Set()
  104. // Set pen values for graf port.
  105. {
  106.     ::PenMode(fMode);                            // set pattern transfer mode
  107.     ::PenPat(fPattern);                            // set pattern for pen
  108.     ::PenSize(fWidth, fHigh);                    // set pen size
  109. }
  110.  
  111.  
  112. #pragma segment GraphicsEnv
  113. void TPenEnvironment::Reset()
  114. // Reset pen values for graf port.
  115. {
  116.     ::PenMode(srcOr);                            // reset  pattern transfer mode
  117.     ::PenPat(&qd.black);                        // reset pen pattern
  118.     ::PenSize(1, 1);                            // reset pen size
  119. }
  120.  
  121.  
  122. // _________________________________________________________________________________________________________ //
  123. //    TColorEnvironment member functions.
  124. // CONSTRUCTORS AND DESTRUCTORS
  125. #pragma segment GraphicsEnv
  126. TColorEnvironment::TColorEnvironment(unsigned short red,
  127.                                      unsigned short green,
  128.                                      unsigned short blue)
  129. // Define colors for grafport.
  130. {
  131.     fColor.red = red;
  132.     fColor.green = green;
  133.     fColor.blue = blue;
  134. }
  135.  
  136.  
  137. #pragma segment GraphicsEnv
  138. TColorEnvironment::TColorEnvironment(RGBColor theColor)
  139. // Define RGBValues for grafport.
  140. {
  141.     fColor = theColor;                            // we make use of the bit-fied copying scheme of the compiler
  142. }
  143.  
  144.  
  145. #pragma segment GraphicsEnv
  146. TColorEnvironment::~TColorEnvironment()
  147. // Default destructor -- not used just now.
  148. {
  149. }
  150.  
  151.  
  152. // MAIN INTERFACE
  153. #pragma segment GraphicsEnv
  154. void TColorEnvironment::SetForeground()
  155. // Set foreground color.
  156. {
  157.     ::RGBForeColor(&fColor);
  158. }
  159.  
  160.  
  161. #pragma segment GraphicsEnv
  162. void TColorEnvironment::SetBackground()
  163. // Set background color.
  164. {
  165.     ::RGBBackColor(&fColor);
  166. }
  167.  
  168.  
  169. #pragma segment GraphicsEnv
  170. void TColorEnvironment::Reset()
  171. // Reset grafport to black/white.
  172. {
  173.     ::ForeColor(blackColor);
  174.     ::BackColor(whiteColor);
  175. }
  176.  
  177.  
  178. // _________________________________________________________________________________________________________ //
  179.  
  180. /*    Change History (most recent last):
  181.   No        Init.    Date        Comment
  182.   1            khs        1/2/93        New file
  183.   2            khs        1/7/93        Cleanup
  184. */
  185.